<!-- 优惠券核销 -->
<template>
	<view class="couponspin">
		<view @click="getscanning" class="scanning">
			<image src="../../../static/images/saoyisao.png" mode="aspectFit"></image>
			<text>点击扫描卡包二维码</text>
		</view>
		<view class="item" v-for="(item,index) in list" :key="item.id">
			<p>{{item.name}}</p>
			<p>有效期：{{item.start_time}}-{{item.end_time}}</p>
			<view class="item-bottom">
				<view class="left">	
					<image :src="item.avatar" mode="aspectFit"></image>
					<text>{{item.nickname}}</text>
				</view>
				<text>{{item.create_time}}</text>
			</view>
		</view>
		<p class="b-p">没有更多核销记录了</p>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import {shareMixins} from '../../../mixins/share.js'
	export default {
		mixins:[shareMixins],
		data() {
			return {
				shareData: {
				    title: '空港卡券联盟商户端',
				    path: '/pages/mine/mine' // 分享的页面路径
				},
				coupon_code:'',
				pindex:1,
				list:[]
			}
		},
		onShow() {
			this.list = []
			this.getCouponOffRecord()
		},
		onReachBottom(){
			this.pindex++
			this.list = []
			this.getCouponOffRecord()
		},
		methods: {
			getscanning(){//扫描二维码
				var _this = this
				uni.scanCode({
				    scanType: ['qrCode'],
				    success: function (res) {
						_this.coupon_code = res.result
						// console.log(_this.coupon_code)
						_this.verification()
				    },
					fail: (err) => {
						// console.log(err)
						uni.showToast({
							icon:'none',
						    title: '扫码失败，请重试！',
						    duration: 2000
						});
					}
				});
			},
			async verification(){//核销方法
				var data = {
					coupon_code: this.coupon_code
				}
				const res = await this.$myRequest({
					url:'/api/businessCoupon/offCoupon'+this.$u.queryParams(data),
					method:'POST'
				}).then((res) => {
					// console.log()
					if(res.data.code == 200){
						this.$refs.uToast.show({
							title:res.data.msg,
							type:'success'
						})
					}else{
						this.$refs.uToast.show({
							title:res.data.msg,
							type:'error'
						})
					}
				})
			},
			async getCouponOffRecord(){//核销记录
				var data = {
					pindex:this.pindex,
					psize:5
				}
				const res = await this.$myRequest({
					url:'/api/businessCoupon/getCouponOffRecord'+this.$u.queryParams(data),
				}).then((res) => {
					if(res.data.code == 200){
						this.list = [...this.list,...res.data.data.data]
					}else{
						this.$refs.uToast.show({
							title:res.data.msg,
							type:'error'
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.couponspin{
		padding: 40rpx 32rpx 0 32rpx;
		.scanning{
			display: flex;
			align-items: center;
			justify-content: center;
			background-color: #FFFFFF;
			border-radius: 20rpx;
			height: 76rpx;
			margin-bottom: 40rpx;
			image{
				width: 28rpx;
				height: 28rpx;
				margin-right: 20rpx;
			}
			text{
				font-size: 28rpx;
				color: #EC5F2F;
			}
		}
		.item{
			margin-top: 24rpx;
			background-color: #FFFFFF;
			padding: 30rpx 24rpx 18rpx 34rpx;
			border-radius: 20rpx;
			p{
				font-size: 40rpx;
				font-weight: bold;
				color: #3C3C3C;
				margin-bottom: 8rpx;
			}
			p:nth-child(2){
				font-size: 24rpx;
				font-weight: bold;
				color: #8B8B8B;
				margin-bottom: 26rpx;
			}
			.item-bottom{
				padding: 14rpx 0 0 0;
				display: flex;
				align-items: center;
				justify-content: space-between;
				border-top: 2rpx dashed #CCCCCC;
				.left{
					display: flex;
					align-items: center;
					image{
						width: 72rpx;
						height: 72rpx;
						border-radius: 50%;
					}
					text{
						font-size: 32rpx;
						color: #731400;
						font-weight: bold;
						margin-left: 16rpx;
					}
				}
				text{
					font-size: 24rpx;
					color: #8B8B8B;
				}
			}
		}
		.b-p{
			font-size: 24rpx;
			color: #8B8B8B;
			margin-top: 100rpx;
			display: flex;
			justify-content: center;
		}
	}
</style>
